<?

//判断是否有数据隔离，就是只能查询自己负责的人的信息
//全公开；仅所属；所属及无所属
if($member_setting['visitmod']=="全公开")
{
    $visitmod_wherw="";
}


if($member_setting['visitmod']=="仅所属")
{
    $visitmod_where=" and agentnid = '".$_SESSION['nid']."'";
}


if($member_setting['visitmod']=="所属及无所属")
{
    $visitmod_where=" and ( agentnid = '".$_SESSION['nid']."' or agentnid = '' or agentnid is null)";
}








$_REQUEST['select_keywords'] = trim($_REQUEST['select_keywords']);

//同意加上and，然后去除左边的and就可以了。
if($_REQUEST['select_keywords'])
{
    $keywords=" and (nickname LIKE '%".$_REQUEST['select_keywords']."%' OR phone LIKE '%".$_REQUEST['select_keywords']."%' )";
    $keywords_url="&select_keywords=".$_REQUEST['select_keywords'];
}
else
{
    $keywords="";
    $keywords_url="";
}

if($_REQUEST['tag'])
{
    $tag_str=" and tag LIKE '%".$_REQUEST['tag']."%' ";
    $tag_url="&tag=".$_REQUEST['tag'];
}
else
{
    $tag_str="";
    $tag_url="";
}

if($_REQUEST['leader'] == '是')
{
    $leader_str=" and leader = '".$_REQUEST['leader']."' ";
    $leader_url="&leader=".$_REQUEST['leader'];
}
else
{
    $leader_str="";
    $leader_url="";
}

if($_REQUEST['official'] == '是')
{
    $official_str=" and t2.openid IS NOT NULL ";
    $official_url="&official=".$_REQUEST['official'];
}else if($_REQUEST['official'] == '否'){
    $official_str=" and t2.openid IS NULL ";
    $official_url="&official=".$_REQUEST['official'];
}else{
    $official_str="";
    $official_url="";
}

if($_REQUEST['select_startday'])
{
    $start_date=$_REQUEST['select_startday'];
    $start_date_str=" and createtime >= '".$start_date."'";
    $start_date_url="&select_startday=".$_REQUEST['select_startday'];
}
else
{
    $start_date_str="";
    $start_date_url="";
}




if($_REQUEST['select_endday'])
{
    $end_date=$_REQUEST['select_endday'];
    $end_date_str=" and createtime <= '".$end_date."'";
    $end_date_url="&select_endday=".$_REQUEST['select_endday'];
}
else
{
    $end_date_str="";
    $end_date_url="";
}



if($_REQUEST['coupon_now'])
{
    $coupon_now=$_REQUEST['coupon_now'];
    $coupon_now_url="&nid=".$_REQUEST['coupon_now'];
}
else
{
    $coupon_now_url="";
}








if($sortorder)
{
    $sortorder="order by ".$sortorder;
}
else
{
    $sortorder="";
}



//生成翻页用连接地址。

//select_keywords=&select_paystatus=全部&select_graduate=全部&select_departmentid=7&select_license=全部&select_startday=2017-06-01&select_endday=2017-06-20
//select_keywords=欠费&select_start_date=2017-06-21&select_end_date=2017-06-18


$pagenumber_url = "&nowpageid=" . $_REQUEST['nowpageid'];
$sys_part   = "&sys_part=" . $_REQUEST['sys_part'];
$term_nid       = "&term_nid=" . $_REQUEST['nid'];





$url_str=$keywords_url.$start_date_url.$end_date_url.$tag_url.$coupon_now_url.$leader_url.$official_url;
$select_str=$keywords.$visitmod_where.$start_date_str.$end_date_str.$tag_str.$leader_str.$official_str;



//设置需要搜索的表格的前缀后缀
    $table_suffix = "member";
    $table = $table_Prefix . $table_suffix;


     $sqlstr="SELECT COUNT(1) FROM $table LEFT JOIN athlon_wechat_member t2 ON athlon_member.unionid = t2.unionid  where 1=1 ".$select_str;

    $query = do_query($sqlstr);
    $sum = mysqli_fetch_array($query)[0];


//设置翻页代码相关内容

$nowpageid = 1;
$detailnum = 100    ; //每页显示多少个产品
$plate['page_list_num']=$detailnum;

if ($_REQUEST ['nowpageid']) {
    $nowpageid = $_REQUEST ['nowpageid'];
} else {
    $nowpageid = 1;
}


//计算一下结果，从那条数据开始显示
$detailstar = ($nowpageid - 1) * $detailnum;


if ($sum) {

    if ($sum < $detailnum) {
        $page_count = 1;
        $detailnum = $sum;
    } //如果总数据量小于$Pagenum,（pagenum作为每页显示数据的条数，）那么只有一页,而pagenum也更改为sum 


    else if ($sum % $detailnum) {
        $page_count = (int)($sum / $detailnum) + 1;
    }
    //取总数据量除以每页数的余数 
    //如果有余数，则页数等于总数据量除以每页数的结果取整再加一


    else {
        $page_count = $sum / $detailnum;
    }
    //如果没有余数，则页数等于总数据量除以每页数的结果 

} else {
    $page_count = 0;
    $detailnum = 0;
}


$lastpage = $page_count;
$prepage = $nowpageid - 1;
$nextpage = $nowpageid + 1;


if ($nowpageid == 1) {
    $prepage = 1;
}


if ($nowpageid == $page_count) {

    if ($sum <= $detailnum) //总数数据少于每页显示数目，就把循环改成总数数目
    {
        $detailnum = $sum;
        $nextpage = $nowpageid;
    } else {
        $nextpage = $nowpageid;
        $detailnum = fmod($sum, $detailnum);
        if ($detailnum == 0) //这个if是因为当数据正好30条，能除尽的话，最后一页就会因为fmod能整除的缘故，最后一页不显示数据
        {
            $detailnum = $plate['page_list_num'];
        }
    }
    //如果现在页数等于总页数（总页数上面求出，最后一页不够循环数的时候），那么最后一页的detailnum就会等于余下数据(不足一页)的数目.

}


//设置需要搜索的表格的排序项和升降项
//$sort = "leader desc ,leader_apply asc , nid desc";
$sort = "field(leader_apply,'驳回','申请中','通过') desc,nid desc";



   $sqlstr="select athlon_member.*,t2.openid from $table LEFT JOIN athlon_wechat_member t2 ON athlon_member.unionid = t2.unionid  where 1=1 ".$select_str." ORDER BY $sort  limit $detailstar , $detailnum";

	$result = do_query($sqlstr);


while ($row = mysqli_fetch_assoc($result)) {
    $detail[]           = $row;
}


mysqli_close($con);

?>
